/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.soa.service.busi.wx;

import com.lianzt.commondata.AbstractCommonData;
import com.lianzt.commondata.DataConvertFactory;
import com.lianzt.exception.InstanceDataException;
import com.soa.exception.GlobalException;
import com.soa.service.BaseService;
import com.soa.util.wx.TrffUtil;
import java.util.logging.Level;
import javax.annotation.Resource;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 *  S40001
 * 查询检验机构信息，返回主页面
 * @author chang
 */
@Service
public class MainService extends BaseService{
    @Resource 
    private TrffUtil trffUtil;
    private org.slf4j.Logger log = LoggerFactory.getLogger(MainService.class);
    @Override
    public String[] keys() {
        return null;
    }

    @Override
    public void execute(AbstractCommonData in, AbstractCommonData inhead, AbstractCommonData out, AbstractCommonData outhead) {
        AbstractCommonData session = getSession(in);
        //调用接口查询检测站信息
        AbstractCommonData abs = DataConvertFactory.getInstance();
        abs.putStringValue("serviceName", "getJczxx");
        if(in.containsKey("jczmc")){
            abs.putStringValue("jczmc", in.getStringValue("jczmc"));
        }
        String res = trffUtil.Nwjkdy(abs);
        AbstractCommonData resp=null;
        try {
            resp = DataConvertFactory.getInstanceByJson(res);
            log.debug("接收到检测站信息---------->>>"+resp);
            if(resp==null){
                out.putStringValue("errMsg", "调用接口返回数据为空！");
                 out.putStringValue("view", "/wx_error");
                throw new GlobalException(4000100,"调用接口返回数据为空！");
            }else{
                String restate = resp.getStringValue("restate");
                if("-1".equals(restate)){
                    out.putStringValue("errMsg", "调用接口处理异常！");
                    out.putStringValue("view", "/wx_error");
                    throw new GlobalException(4000101,"调用接口处理异常！");
                }else{
                    out.putArrayValue("result", resp.getArrayValue("jcz"));
                    if(!session.containsKey("jczxx")){
                        session.putArrayValue("jczxx", resp.getArrayValue("jcz"));
                    }
                    out.putStringValue("view", "/wx/index");
                }
            }
            
        } catch (InstanceDataException ex) {
           log.error("调用接口出错", ex);
        }
    }
    
}
